const userService = require('../../services/dao/app/user');
const sessionFilter = require('../../middlewares/adminSessionMiddleware');
const log4js = require('../../utils/log4js');
const vip = module.exports;

vip.get_vipList = [sessionFilter, (req, res) => {
    let pageLimit = pager.requestFilter(req);

    userService.userList(pageLimit.page, pageLimit.limit, req.query || {}).then((data) => {
        res.jsonWrap(data);
    }).catch((e) => {
        log4js.error(e);
        res.jsonWrap(null, 1, e.message);
    });
}];

// 修改用户信息
vip.post_saveVipUser = [sessionFilter, (req, res) => {
    let args = req.body || {};
    userService.saveUser(args).then((data) => {
        res.jsonWrap(data);
    }).catch((e) => {
        log4js.error(e);
        res.jsonWrap(null, 1, e.message);
    });
}];

// 个人中心统计数据
vip.get_stat = [sessionFilter, (req, res) => {
    userService.stat(req.query.id || '').then((data) => {
        res.jsonWrap(data);
    }).catch((e) => {
        log4js.error(e);
        res.jsonWrap(null, 1, e.message);
    });
}];
